home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / chasm4.zip / CHMOD.ASM < prev    next >
Assembly Source File  |  1984-05-03  |  11KB  |  314 lines

  1. ;================================================
  2. ; CHMOD    Version 1.1    5/3/84
  3. ;
  4. ;         by David Whitman
  5. ;
  6. ; Utility to examine and modify the read/write
  7. ; mode of a file under DOS 2.0.
  8. ;
  9. ; Syntax:
  10. ;
  11. ; CHMOD [d:][path] [filespec] [/N] [/R] [/S] [/H]
  12. ;
  13. ; If no file is specified, a help message is printed,
  14. ; summarizing the CHMOD command syntax.
  15. ;
  16. ; The attribute byte of the specified file is set
  17. ; according to the selected options:
  18. ;
  19. ;     /N - normal file
  20. ;     /R - read only
  21. ;     /S - system file
  22. ;     /H - hidden file
  23. ;
  24. ; Multiple options may be selected.  /N will cancel
  25. ; options preceding it in the command line.
  26. ;
  27. ; If no options are selected, a report on the current
  28. ; mode of the specified file is sent to the standard output.
  29. ;
  30. ; On exit, ERRORLEVEL is set to reflect the current file
  31. ; mode, and/or the success of the change, as follows:
  32. ;
  33. ;   normal file      --> 0
  34. ;   read only file   --> 1
  35. ;   hidden file      --> 2
  36. ;   system file      --> 4
  37. ;   failed operation --> 8
  38. ;
  39. ; Requires DOS 2.0, will abort under earlier versions.
  40. ;
  41. ; This source file is in CHASM assembler syntax.
  42. ;======================================================
  43.  
  44. ;==========
  45. ; EQUATES
  46. ;==========
  47.  
  48. @chmod     equ    43H        ;change file mode
  49. @dosver    equ    30H        ;get DOS version number
  50. @exit      equ    4CH        ;set ERRORLEVEL and exit
  51. @prnstr    equ    09H        ;print string
  52.  
  53. normal     equ    00H
  54. readonly   equ    01H
  55. hidden     equ    02H
  56. system     equ    04H
  57. failure    equ    08H
  58.  
  59. true       equ    0FFH       ;boolean values
  60. false      equ    00H
  61.  
  62. cr         equ    0DH        ;carriage return
  63. lf         equ    0AH        ;line feed
  64. beep       equ    07H        ;bell
  65.  
  66. param_area  equ   [81H]      ;unformatted parameter area
  67. param_count equ   [80H]      ;number of characters in above
  68.  
  69. ;===========================================================
  70.  
  71. chmod      proc   near
  72.            call   chkdos              ;test for proper DOS
  73.            call   parsefile           ;parse path/filename
  74.            call   options             ;parse options, set flags
  75.            call   doit                ;perform specified action
  76.            call   cleanup             ;final processing, exit
  77.            mov    al, opflag          ;set errorlevel with current attributes
  78.            mov    ah, @exit           ;and exit
  79.            int    21H
  80.            endp
  81.  
  82. ;=================================================
  83. ; SUBROUTINE CHKDOS
  84. ; Checks for proper DOS, exits if not 2.0 or above
  85. ;=================================================
  86. chkdos     proc   near
  87.            mov    ah, @dosver         ;get dos version number
  88.            int    21H                 ;with dos call
  89.            cmp    al, 2               ;2.0 or over?
  90.            jae    a1                  ;yes, skip
  91.  
  92.            mov    ah, @prnstr         ;no, bitch
  93.            mov    dx, offset(baddos)  ;point to message
  94.            int    21H                 ;and print it
  95.            pop    ax                  ;reset stack
  96.            int    20H                 ;and exit
  97. a1
  98.            ret
  99.  
  100. baddos     db     beep, cr, lf, 'This program requires DOS 2.0!' cr, lf, '$'
  101.            endp
  102.  
  103. ;===================================================
  104. ; SUBROUTINE PARSEFILE
  105. ; Scans the parameter area for a path/filename.
  106. ; Sets PATHPTR to point to the name, and terminates
  107. ; it with a 0, to make an ASCIIZ string.
  108. ;
  109. ; If no name is found, ERRORLEVEL is set to 8,
  110. ; and control is passed back to DOS.
  111. ;===================================================
  112. parsefile  proc   near
  113.  
  114.            xor    ch,ch               ;cx <== # of parameter characters
  115.            mov    cl, param_count     ;    "
  116.            mov    di, offset(param_area)
  117.            mov    al, ' '             ;search for first non-blank
  118.            rep
  119.            scasb
  120.            jcxz   berror              ;nothing? bitch
  121.  
  122.            dec    di                  ;back up to character found
  123.            inc    cx                  ; "
  124.            cmpb   [di], '/'           ;are we into the options?
  125.            jne    b1                  ;no, skip
  126. berror     mov    ah, @prnstr         ;yes, print help message
  127.            mov    dx, offset(nofile)
  128.            int    21H
  129.            pop    ax                  ;reset stack
  130.            mov    ah, @exit           ;set error level and exit
  131.            mov    al, failure
  132.            int    21H
  133.  
  134. b1
  135.            mov    pathptr, di         ;otherwise point to pathname
  136.  
  137.            repne                      ;now search for next blank
  138.            scasb
  139.            jcxz   b2                  ;reached end of data?
  140.            dec    di                  ;nope, back up to last non-blank
  141.            inc    cx                  ; "
  142. b2         movb   [di], 00H           ;ASCIIZ string terminator
  143.            ret
  144.  
  145. pathptr    db   00H, 00H            ;pointer to path/filename
  146. nofile     db   cr, lf
  147.            db   'CHMOD version 1.1' cr lf
  148.            db   cr lf
  149.            db   'Syntax:  CHMOD [d:][path] [filespec] [/N] [/R] [/S] [/H]'
  150.            db   cr lf cr lf
  151.            db   'The attribute byte of the specified file is set' cr lf
  152.            db   'according to the selected options:' cr lf
  153.            db   cr lf
  154.            db   '     /N - normal file' cr lf
  155.            db   '     /R - read only' cr lf
  156.            db   '     /S - system file' cr lf
  157.            db   '     /H - hidden file' cr lf
  158.            db   cr lf
  159.            db   'Multiple options may be selected.' cr lf
  160.            db   cr lf
  161.            db   'If no options are selected, a report on the current mode' cr lf
  162.            db   'of the specified file is sent to STDOUT and ERRORLEVEL'cr lf
  163.            db   'is set to the value of the file attribute byte. ' cr lf cr lf
  164.            db   '$'
  165.            endp
  166. ;=====================================================
  167. ; SUBROUTINE OPTIONS
  168. ; Scans the command line for options, and builds
  169. ; the new attribute byte in OPFLAG.
  170. ;
  171. ; If options are found, OPFOUND is set true, otherwise
  172. ; it remains false.
  173. ;======================================================
  174. options    proc near
  175.                                       ;cx still has number of chars. left,
  176.                                       ;di points to current position.
  177.  
  178. c1         mov   al, '/'              ;options marked with '/'
  179.            repnz                      ;scan for options
  180.            scasb
  181.            jcxz  cexit                ;reached end
  182.  
  183.            mov   al, [di]             ;get option character
  184.            and   al, 0DFH             ;guarantees upper case
  185.  
  186.            cmp   al, 'N'              ;normal file?
  187.            jne   c2                   ;no, skip
  188.            movb  opflag, normal       ;yes, clear all bits
  189.            movb  opfound, true        ;set found flag
  190.            jmps  c1                   ;and loop
  191.  
  192. c2         cmp   al, 'R'              ;read only?
  193.            jne   c3                   ;no, skip
  194.            orb   opflag, readonly     ;yes, set option flag
  195.            movb  opfound, true        ;set found flag
  196.            jmps  c1                   ;and loop
  197.  
  198. c3         cmp   al, 'S'              ;system?
  199.            jne   c4                   ;no, skip
  200.            orb   opflag, system       ;yes, set option flag
  201.            movb  opfound, true        ;set found flag
  202.            jmps  c1                   ;and loop
  203.  
  204. c4         cmp   al, 'H'              ;hidden?
  205.            jne   c1                   ;no, just loop
  206.            orb   opflag, hidden       ;yes, set option flag
  207.            movb  opfound, true        ;set found flag
  208.            jmps  c1                   ;and loop
  209.  
  210. cexit      ret
  211.  
  212. opflag     db    00H                  ;options selected - new attribute byte
  213. opfound    db    00H                  ;if non-zero, an option was decoded
  214.            endp
  215.  
  216. ;========================================================
  217. ; SUBROUTINE DOIT
  218. ; Does the actual work.  Either sets new file attribute,
  219. ; or reads the existing attribute.
  220. ;========================================================
  221. doit       proc  near